﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Collections.ObjectModel;
using System.ComponentModel;

namespace HomeMediaBrowser
{
    public enum ThumbType
    {
        THUMB_FOLDER,
        THUMB_VIDEO,
        THUMB_AUDIO,
        THUMB_IMAGE,
        THUMB_OTHER,
        THUMB_ADDSERVERFOLDER,
    };
    public class UIListItemData : INotifyPropertyChanged
    {
        public UIListItemData()
        {
            ThumbVisible = Visibility.Hidden;
            ThumbDefVisible = Visibility.Visible;
            CanPlay = false;
            CanDownload = false;
            IsServer = false;
            downloadFinish = false;
            downloadPercent = 0;
            isDownloading = true;
            return;
        }
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName) 
        {
            if (PropertyChanged != null) 
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        public Visibility ThumbVisible
        {
            get { return thumbVisible; }
            set
            {
                thumbVisible = value;
                NotifyPropertyChanged("ThumbVisible");
            }
        }
        public Visibility ThumbDefVisible
        {
            get { return thumbDefVisible; }
            set
            {
                thumbDefVisible = value;
                NotifyPropertyChanged("ThumbDefVisible");
            }
        }
        public Boolean CanPlay
        {
            get { return canPlay; }
            set
            {
                canPlay = value;
                NotifyPropertyChanged("CanPlay");
            }
        }
        public Boolean CanDownload
        {
            get { return canDownload; }
            set
            {
                canDownload = value;
                NotifyPropertyChanged("CanDownload");
            }
        }
        public int DownloadPercent
        {
            get { return downloadPercent; }
            set
            {
                downloadPercent = value;
                NotifyPropertyChanged("DownloadPercent");
            }
        }
        public Boolean DownloadFinish
        {
            get { return downloadFinish; }
            set
            {
                downloadFinish = value;
                NotifyPropertyChanged("DownloadFinish");
            }
        }
        public Boolean IsDownloading
        {
            get { return isDownloading; }
            set
            {
                isDownloading = value;
                NotifyPropertyChanged("IsDownloading");
            }
        }
        public ThumbType Type { get; set; }
        public string Path{get;set;}
        public string Name { get; set; }
        public string ThumbPath { get; set; }
        public Boolean IsServer { get; set; }
        public ImageBrush ThumbBrush { get; set; }
        public ImageBrush ThumbBrushDef { get; set; }
        public Visibility thumbVisible { get; set; }
        public Visibility thumbDefVisible { get; set; }

        //for download item
        public int downloadPercent { get; set; }
        public Boolean downloadFinish { get; set; } //finish will show play button
        public Boolean isDownloading { get; set; }

        //for thumb item
        public Boolean canPlay { get; set; }
        public Boolean canDownload { get; set; }
        
        public void SetThumbVisible(Visibility Vis) {
            if (Vis == Visibility.Visible)
            {
                ThumbDefVisible = Visibility.Hidden;
            }
            else
            {
                ThumbDefVisible = Visibility.Visible;
            }
            ThumbVisible = Vis;
        }

        static public ImageBrush FolderThumb = new ImageBrush(new BitmapImage(new Uri("Skins\\folder.png", UriKind.Relative)));
        static public ImageBrush VideoThumb = new ImageBrush(new BitmapImage(new Uri("Skins\\media.png",UriKind.Relative)));
        static public ImageBrush AudioThumb = new ImageBrush(new BitmapImage(new Uri("Skins\\audio.png", UriKind.Relative)));
        static public ImageBrush ImageThumb = new ImageBrush(new BitmapImage(new Uri("Skins\\photo.png", UriKind.Relative)));
        static public ImageBrush OtherThumb = new ImageBrush(new BitmapImage(new Uri("Skins\\media.png", UriKind.Relative)));
        static public ImageBrush AddThumb = new ImageBrush(new BitmapImage(new Uri("Skins\\Add.png", UriKind.Relative)));

        //must do it to show thumbnail.
        public int InitThumb(string ThumbnailPath)
        {
            ThumbPath = ThumbnailPath;
            BitmapImage ImageS = new BitmapImage();
            ImageS.UriSource = new Uri(ThumbnailPath);
            ThumbBrush = new ImageBrush(ImageS);

            return 0;
        }
        public int InitThumb(ThumbType Typ)
        {
            Type = Typ;
            switch (Typ)
            {
                case ThumbType.THUMB_FOLDER:
                    ThumbBrushDef = new ImageBrush(FolderThumb.ImageSource);
                    CanDownload = false;
                    CanPlay = false;
                    break;
                case ThumbType.THUMB_VIDEO:
                    ThumbBrushDef = new ImageBrush(VideoThumb.ImageSource);
                    CanDownload = true;
                    CanPlay = true;
                    break;
                case ThumbType.THUMB_AUDIO:
                    ThumbBrushDef = new ImageBrush(AudioThumb.ImageSource);
                    CanDownload = true;
                    CanPlay = true;
                    break;
                case ThumbType.THUMB_IMAGE:
                    ThumbBrushDef = new ImageBrush(ImageThumb.ImageSource);
                    CanDownload = true;
                    CanPlay = true;
                    break;
                case ThumbType.THUMB_ADDSERVERFOLDER:
                    ThumbBrushDef = new ImageBrush(AddThumb.ImageSource);
                    CanDownload = false;
                    CanPlay = false;
                    break;
                case ThumbType.THUMB_OTHER:
                default:
                    ThumbBrushDef = new ImageBrush(OtherThumb.ImageSource);
                    CanDownload = true;
                    CanPlay = false;
                    break;
            }
            ThumbBrush = new ImageBrush(OtherThumb.ImageSource);
            return 0;
        }
    }
    public partial class MediaLibaryList : ObservableCollection<UIListItemData>
    {

        public MediaLibaryList()
            : base()
        {

        }

    }
    public class UITabItemData:INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public UITabItemData(string H, string P, PlainView V)
        {
            Header = H;
            Path = P;
            IsSelected = false;
            //View = V;
        }
        public UITabItemData(string H, string P):this(H,P,null)
        {
            
        }       
        public string Header { get; set; }
        public string Path { get; set; }
        public PlainView View { get; set; }
        public Boolean IsSelected
        {
            get { return isSelected; }
            set
            {
                isSelected = value;
                NotifyPropertyChanged("IsSelected");
            }
        }
        public Boolean isSelected { get; set; }
    }
    public partial class TabList : ObservableCollection<UITabItemData>
    {

        public TabList()
            : base()
        {

        }

    }
    public partial class PathList:ObservableCollection<UITabItemData>
    {
        public PathList()
            : base()
        {

        }
    }
}
